using System;
using System.Threading;
using System.Collections.Generic;
using System.Text;
using Ndo;

namespace Ndo.Box.Testing
{
    public interface IMyDictionary<TKey, TValue>
    {
        [Reader]
        int Count { get;}
        TValue this[TKey key]
        {
            [Reader]
            get; 
            [Writer]
            set;
        }

        [Reader]
        bool ContainsKey(TKey key);

        [Writer]
        void Add(TKey key, TValue value);

        [Writer]
        bool Remove(TKey key);
    }
    public class MyDictionary<TKey, TValue> : IMyDictionary<TKey, TValue>
    {
        private Dictionary<TKey, TValue> dict = new Dictionary<TKey, TValue>();
        #region IMyDictionary<TKey,TValue> Members

        public int Count
        {
            get { return dict.Count; }
        }

        public TValue this[TKey key]
        {
            get
            {
                Thread.Sleep(1);
                return dict[key];
            }
            set
            {
                Thread.Sleep(1);
                dict[key] = value;
            }
        }

        public bool ContainsKey(TKey key)
        {
            Thread.Sleep(1);
            return dict.ContainsKey(key);
        }

        public void Add(TKey key, TValue value)
        {
            Thread.Sleep(1);
            dict.Add(key, value);
        }

        public bool Remove(TKey key)
        {
            Thread.Sleep(1);
            return dict.Remove(key);
        }

        #endregion
    }
}
